//---------------------------------------------------------------------------

#ifndef ServerH
#define ServerH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <stdio.h>
#include "winsock2.h"
//---------------------------------------------------------------------------

struct ISocket {
    virtual void onRecv(UnicodeString data) = 0;
};


class TListenThrd : public TThread {
private:    // User declarations
	bool fSuspended;
	ISocket *fServer;
	SOCKET fListenSocket;
	SOCKET fClientSocket;

protected:  // User declarations
    void __fastcall Execute();
public:     // User declarations
	__fastcall TListenThrd(SOCKET aListenSocket, bool suspended, ISocket* aServer) : TThread(suspended) {
        fServer = aServer;
		fListenSocket = aListenSocket;
		fSuspended = suspended;
	};
};

class TForm1 : public TForm,ISocket
{
__published:	// IDE-managed Components
	TMemo *Memo1;
	void __fastcall FormCreate(TObject *Sender);
private:	// User declarations
	WSADATA fWSAData;
	SOCKET fListenSocket;
	SOCKET fClientSocket;
	TListenThrd* fListenThrd;
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
	void onRecv(UnicodeString data);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
